//
//  CustomViewController.swift
//  SyanYan
//
//  Created by Yanyan Jiang on 2018/6/5.
//  Copyright © 2018年 Yanyan Jiang. All rights reserved.
//

import UIKit

class CustomViewControllerOne: ViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.classInitPropertyMethod()
    }
    
    override func viewWillAppear(_ animated: Bool){
        super.viewWillAppear(animated)
    }
    
    override func viewWillDisappear(_ animated: Bool){
        super.viewWillDisappear(animated)
    }

    public func learnSwiftMethod() -> (){
        let constantL: Float = 1.0
        let widthStr: String = "The Width is"
        let width: Float = 99
        let widthPlus = widthStr + String(width) + String(constantL)
        let ggg = widthStr + "I Am Learn Swift\(constantL + width) And You \(widthPlus)"
        print(ggg)
        var shoppingList = ["water", "tree", "orange", "apple"]
        shoppingList[1] = "bread"
    }
    
    //类、继承、初始化、属性
    public func classInitPropertyMethod() ->(){
        let vericle = Vericle()
        print(vericle.description)
        vericle.numberOfWheels = 100
        print(vericle.description)
        
        let myBicycle = Bicycle()
        print(myBicycle.description)
        
        let myCar = Car()
        print(myCar.description)
        
        let myParentsCar = ParentsCar()
        myParentsCar.speed = 77.0
        print(myParentsCar.speed)
    }
    
    
    //有参数有返回值的方法
    func parameterMethods(name: String, age: Int) -> (String){
        return "\(name)的年龄是\(age)岁"
    }
    
    //结构体、常量与变量、枚举、扩展、泛型
    override func didReceiveMemoryWarning(){
        super.didReceiveMemoryWarning()
    }
    
}


//类名可以与文件名不一样

//class Vericle {
//    //properties 属性  有储值属性（stored Properties） 有算值属性(Computed Properties)
//    //methods 方法
//    //initializers 初始化
//    var numberOfWheels = 0 //只有可能值才能接收为空nil
//    var nnValue = ""
//    //description 就是算值属性 因为每次取出来的是不一样的所以是var
//    var description: String {
//        //只有get 是只读属性(也可以把get省略) 既有get 又有set 是可读可写属性
//        get{
//          return "\(numberOfWheels)个轮子"
//        }
////        set {
////           nnValue = newValue;
////        }
//    }
//}

//为什么swift中的类不需要继承
//class Bicycle: Vericle {
//    override init() {
//        super.init()
//        numberOfWheels = 2
//    }
//}


//class Car: Vericle {
//    var speed = 0.0
//    override init() {
//        super.init()
//        numberOfWheels = 4
//    }
//    override var description: String{
//        get{
//            return super.description + ",每小时 \(speed)英里"
//        }
//    }
//}

//class ParentsCar: Car {
//    override init() {
//    }
//    //重写储值属性 property observer 属性观察
//    override var speed: Double{
//        willSet{
//            print("willSet\(newValue)")
//            //在这里可以通过 newValue 变量访问新值
//            if newValue>65.0 {
//                print("你的速度太大了亲")
//            }
//        }
//        didSet{
//            //在这里可以通过 oldValue 变量访问旧值
//            print("didSet\(oldValue)")
//        }
//    }
//}

//class  Counter  {
//    var count = 0
//    func incrementBy(amount: Int) -> () {
//        count += amount
//    }
//}



